import { request } from "@/utils/service"
import type * as Project from "./types/project"
import type * as User from "@/api/user/types/user"

/** 增/改 */
export function saveProjectDataApi(data: Project.SaveProjectRequestData) {
  return request({
    url: "project/save",
    method: "post",
    data
  })
}

/** 删 */
export function deleteProjectDataApi(id: number) {
  return request({
    url: `project/delete/${id}`,
    method: "post"
  })
}

//  name是否可用
export function checkNameRepeat(name: string, id: number) {
  return request<ApiResponseData<boolean>>({
    url: `project/checkName/${name}/${id}`,
    method: "post"
  })
}

/** 查 */
export function getProjectDataApi(data: Project.ProjectRequestData) {
  return request<Project.ProjectResponseData>({
    url: "project/list",
    method: "post",
    data
  })
}
/**
 * 修改项目状态
 */
export function updateStatusApi(id: number, status: string) {
  return request<ApiResponseData<number>>({
    url: `/project/updateStatus/${status}/${id}`,
    method: "post"
  })
}

// 项目下的用户列表
export function projectUserDataApi(id: number) {
  return request<ApiResponseData<User.UserData[]>>({
    url: `/project/projectUser/${id}`,
    method: "get"
  })
}

// 供项目选择的人员列表:  尚未被选择的其他人员
export function projectSelectUserListApi(data: Project.ProjectUserRequestData) {
  return request<ApiResponseData<User.UserData[]>>({
    url: "/project/selectUser",
    method: "post",
    data
  })
}

// 新增项目的用户  /project/addProjectUser
export function insertProjectUserApi(data: Project.ProjectUserInsertData) {
  return request<ApiResponseData<number>>({
    url: "/project/addProjectUser",
    method: "post",
    data
  })
}

// 删除项目下的用户  /project/delete/{projectId}/{userId}
export function deleteProjectUserApi(projectId: number, userId: number) {
  return request<ApiResponseData<User.UserData[]>>({
    url: `/project/delete/${projectId}/${userId}`,
    method: "post"
  })
}
